#!/bin/sh

#
# Test file concatenation
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

cat >$CONFIG <<EOF
file-resource TEST {
        host-path = "${TESTFILE_1K};${TESTFILE_150K};${TESTFILE_1K_CORRUPT}"
}

task complete {
	on-resource TEST { raw_write(0) }
}
EOF

cat >$EXPECTED_META_CONF <<EOF
file-resource "TEST" {
length=152048
blake2b-256="792ac899e67b886626954873c976baa23d9d9c3b379410515041e9e94687e13a"
}
task "complete" {
on-resource "TEST" {
funlist = {"2", "raw_write", "0"}
}
}
EOF

$FWUP_CREATE -c -f $CONFIG -o $FWFILE

# Check that the zip file was created as expected
check_meta_conf
cat $TESTFILE_1K $TESTFILE_150K $TESTFILE_1K_CORRUPT > $WORK/cat.bin
cmp $WORK/cat.bin $UNZIPDIR/data/TEST

# Check that applying the firmware does the expected thing
$FWUP_APPLY -a -d $IMGFILE -i $FWFILE -t complete
cmp_bytes 151024 $WORK/cat.bin $IMGFILE

# Check that the verify logic works on this file
$FWUP_VERIFY -V -i $FWFILE
